#RequireAdmin
#include <Constants.au3>

Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)
Opt("GUIOnEventMode", 1)

TraySetToolTip("D2NT Manager")

Run(@ScriptDir&"\D2NT Manager.exe")

$hidden = 0

$d2nt = WinWait("D2NT Manager", "", 5)

TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "click")

If $d2nt = 0 Then
   Msgbox( 64, "Error", "D2NT Manager was unable to start."&@LF&@LF&"Make sure you put this launcher in the same folder as D2NT Manager.")
   Exit
EndIf

While 1
   Sleep(1000)
   If ProcessExists("D2NT Manager.exe")=0 Then Exit
WEnd

Func click()
   If $hidden = 0 Then
      $hidden = 1
      WinSetState($d2nt, "", @SW_HIDE)
   ElseIf $hidden = 1 Then
      $hidden = 0
      WinSetState($d2nt, "", @SW_SHOW)
      Sleep(10)
      WinActivate($d2nt)
   EndIf
EndFunc